<template>
  <div class="cu-common-layout">
    <div class="cu-common-layout-center">
      <el-row class="cu-common-search-box" :gutter="16">
        <el-form @submit.native.prevent>
          <el-col :span="5">
            <el-form-item label="开业日期">
              <el-date-picker v-model="query.openDate" type="daterange" value-format="timestamp" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="辅导校区">
              <el-select v-model="query.campusId" placeholder="辅导校区" filterable clearable>
                <el-option v-for="(item, index) in campusOptions" :key="index" :label="item.fullName" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="管理区域" prop="company">
              <el-select v-model="query.company" placeholder="">
                <el-option v-for="item in companyOptions" :key="item.id" :label="item.fullName" :value="item.enCode" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="是否达标">
              <el-select v-model="query.reach" placeholder="辅导校区" filterable clearable>
                <el-option key="0" label="开业招生达标" :value="true" />
                <el-option key="1" label="招生未达标，持续跟进" :value="false" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="审核状态">
              <el-select v-model="query.flowState" placeholder="请选择审核状态" filterable clearable>
                <el-option key="" label="全部" value="" />
                <el-option key="0" label="等待提交" value="0" />
                <el-option key="1" label="等待审核" value="1" />
                <el-option key="2" label="审核通过" value="2" />
                <el-option key="3" label="审核驳回" value="3" />
                <el-option key="4" label="流程撤回" value="4" />
                <el-option key="5" label="审核终止" value="5" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="校区区域">
              <custom-address v-model="query.area" :check-strictly="true" />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="辅导师">
              <userSelect v-model="query.counselor" placeholder="请选择辅导师" />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="预计回访时间">
              <el-date-picker v-model="query.expectedFollowUpDate" type="daterange" value-format="timestamp" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
              <el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="cu-common-layout-main cu-flex-main">
        <div class="cu-common-head">
          <div>
            <el-button v-has="'btn_add'" type="primary" icon="el-icon-plus" @click="addOrUpdateHandle()">新增</el-button>
          </div>
          <div class="cu-common-head-right">
            <el-tooltip effect="dark" content="刷新" placement="top">
              <el-link icon="icon-ym icon-ym-Refresh cu-common-head-icon" :underline="false" @click="reset()" />
            </el-tooltip>
            <screenfull is-container />
          </div>
        </div>
        <custom-table v-loading="listLoading" :data="list">
          <el-table-column v-if="custom.hasP('createTime')" prop="createTime" label="提交时间" align="left" :formatter="custom.tableDateFormat" width="120" />
          <el-table-column v-if="custom.hasP('createUserName')" prop="createUserName" label="提交人" align="left" width="80" />
          <el-table-column v-if="custom.hasP('campusId')" label="辅导校区" prop="campusId" align="left" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.campusId | dynamicText(campusOptions) }}
            </template>
          </el-table-column>
          <el-table-column v-if="custom.hasP('openDate')" prop="openDate" label="开业日期" align="left" :formatter="custom.tableDateFormat" width="120" />
          <el-table-column v-if="custom.hasP('type')" label="开业状态" prop="type" align="center" width="80">
            <template slot-scope="scope">
              {{ scope.row.type | dynamicText(typeOptions) }}
            </template>
          </el-table-column>
          <el-table-column v-if="custom.hasP('counselor')" prop="consultantName" label="辅导师" align="left" width="80" />
          <el-table-column v-if="custom.hasP('tutorialDate')" prop="tutorialDate" label="辅导日期" header-align="center" align="left" width="200">
            <template slot-scope="scope">
              <span v-if="scope.row.tutorialDate != 'null'">
                {{ JSON.parse(scope.row.tutorialDate).join(',') }}
              </span>
            </template>
          </el-table-column>
          <el-table-column v-if="custom.hasP('degreeCount')" prop="degreeCount" label="校区学位" align="left" width="80" />
          <el-table-column v-if="custom.hasP('bedNum')" prop="bedNum" label="校区床位" align="left" width="80" />
          <el-table-column v-if="custom.hasP('regular')" prop="regular" label="正价招生" align="left" width="90" />
          <el-table-column v-if="custom.hasP('lead')" prop="lead" label="引流招生" align="left" width="90" />
          <el-table-column v-if="custom.hasP('summarize')" prop="summarize" label="开业总结" align="left" width="300" show-overflow-tooltip />
          <el-table-column v-if="custom.hasP('expectedFollowUpDate')" prop="expectedFollowUpDate" label="预计回访时间" align="center" width="140" :formatter="custom.tableDateFormat" />

          <el-table-column prop="isStandard" label="是否达标" align="left" width="220">
            <template slot-scope="scope">
              <span v-if="scope.row.isStandard === null || scope.row.isStandard === undefined"></span>
              <span v-else-if="scope.row.isStandard" style="color: #67C23A;">达标</span>
              <span v-else style="color: red">未达标</span>
            </template>
          </el-table-column>
          <el-table-column prop="flowState" label="审核状态" align="center" width="100">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.flowState == 1">等待审核</el-tag>
              <el-tag v-else-if="scope.row.flowState == 2" type="success">审核通过</el-tag>
              <el-tag v-else-if="scope.row.flowState == 3" type="danger">审核驳回</el-tag>
              <el-tag v-else-if="scope.row.flowState == 4" type="danger">流程撤回</el-tag>
              <el-tag v-else-if="scope.row.flowState == 5" type="warning">审核终止</el-tag>
              <el-tag v-else type="info">等待提交</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" fixed="right" width="340" align="center">
            <template slot-scope="scope">
              <el-button type="text" v-has="'btn_edit'" :disabled="[1, 2, 5].indexOf(scope.row.flowState) > -1" @click="addOrUpdateHandle(scope.row.id)">编辑</el-button>
              <el-button type="text" v-has="'btn_remove'" :disabled="[1, 2, 3, 5].indexOf(scope.row.flowState) > -1" @click="handleDel(scope.row.id)" class="cu-table-delBtn">删除</el-button>
              <el-button size="mini" type="text" :disabled="!scope.row.flowState" @click="addOrUpdateHandle(scope.row.id, scope.row.flowState)" v-has="'btn_detail'">详情</el-button>
              <el-button v-if="!scope.row.followUp && canFollowUp(scope.row)" type="text" size="mini" :disabled="!canFollowUp(scope.row)" @click="handleFollowUp(scope.row)" v-has="'btn_followup'">
                <i class="el-icon-plus" style="margin-right: 2px;"></i>
                回访
              </el-button>
              <el-button v-if="scope.row.followUp && canFollowUp(scope.row)" type="text" size="mini" :disabled="!canFollowUp(scope.row)" @click="handleEditFollowUp(scope.row)" v-has="'btn_followup'" style="color: #E6A23C;">
                <i class="el-icon-edit" style="margin-right: 2px;"></i>
                编辑回访
              </el-button>
              <el-button v-if="scope.row.followUp" type="text" size="mini" @click="viewFollowUpDetail(scope.row)" style="color: #409EFF;">
                <i class="el-icon-view" style="margin-right: 2px;"></i>
                回访详情
              </el-button>
            </template>
          </el-table-column>
        </custom-table>
        <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="initData" />
      </div>
    </div>
    <FlowBox v-if="flowVisible" ref="FlowBox" @close="colseFlow" />
    <follow-up-dialog v-if="followUpVisible" ref="followUpDialog" :current-row="currentRow" :edit-data="editFollowUpData" :is-detail="isFollowUpDetail" @refresh="refresh" @close="closeFollowUp" />
  </div>
</template>

<script>
export { default } from './index.js'
</script>
